:Init

@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@pushd %~dp0
@prompt $_
@echo off

@if "%1" == "" goto Usage
@if "%2" == "" goto Usage
@if "%3" == "" goto Usage
@if not exists "%3" goto Usage
@goto Create

:Usage
@echo.
@echo Creates, mounts and formats a new virtual hard drive file.  
@echo.
@echo CREATEVHD letter size [drive:][path]filename
@echo.
@echo   letter      The drive letter to assign to the volume.
@echo   size        Size of the virtual disk, in megabytes (MB).
@echo.
@echo   [drive:][path][filename]
@echo               Specifies the full path the VHD file to mount.
@echo
@goto End

:CheckPaths
@if exists "%1" (
    @echo Drive letter '%1' already in use.
    @goto End
)
@if exists "%3" (
    @echo A file exists at the target location '%3'.
    @goto End
)

:Create
echo create vdisk file="%3" maximum=%2 type=fixed SD="D:P:(A;;GA;;;WD)" "%TEMP%\accelcon.createvhd.script.txt"
echo select vdisk file="%3" >> "%TEMP%\accelcon.createvhd.script.txt"
echo attach vdisk >> "%TEMP%\accelcon.createvhd.script.txt"
echo create partition primary >> "%TEMP%\accelcon.createvhd.script.txt"
echo assign letter=%1 >> "%TEMP%\accelcon.createvhd.script.txt"
echo format fs=ntfs label=vhd quick >> "%TEMP%\accelcon.createvhd.script.txt"
@diskpart.exe -s "%TEMP%\accelcon.createvhd.script.txt"
@ping 1.0.0.0 -n 5 -w 1000 >NUL

REM ~~( END )~~
@echo.
@echo Completed.
@echo.
:End